import axios from 'axios'
import { nanoid } from 'nanoid'
export default {
    namespaced:true,
    actions:{
        addpersonLi(context,value){
            if(value.name.indexOf('李') == 0){
                context.commit('ADD_PERSON',value)
            }else{
                alert('请添加一个姓王的人')
            }
        },
        addpersonServe(context){
            axios.get('https://api.uixsj.cn/hitokoto/get?type=social').then(
                response =>{
                    context.commit('ADD_PERSON',{id:nanoid(),name:response.data})
                },
                error =>{
                     alert(error.message)
                }
            )
        }
    },
    mutations:{
        ADD_PERSON(state,value){
            state.personList.unshift(value)
        }
    },
    state:{
        personList:[
            {id:'001',name:'小明'}
          ]
    },
    getters:{
        fristname(state){
            return state.personList[0].name
        }
    }
}